package com.springmvc.controller;

import com.springmvc.entity.User;
import com.springmvc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @Autowired
    UserService userService;

    /**
     * 跳转到登录界面
     * @return
     */
    @RequestMapping("/login")
    public String login(){

        return "login";
    }

    @RequestMapping(value = "/doLogin")
    public String doLogin(User user, HttpSession session){
        User u = userService.login(user);
        if(u!=null){
            session.setAttribute("user",u);
            return "redirect:/home";
        }

        return "error";
    }

}
